<template>
	<view>
		<uni-nav-bar :statusBar="true" dark title="分组" fixed left-icon="left" @clickLeft="clickLeft">
			<block slot="right">
				<view class="city">
					<view @click="onCreated">
						<uni-icons color="#fff" fontFamily="CustomFont" type="plusempty" :size="20"></uni-icons>
					</view>
				</view>
			</block>
		</uni-nav-bar>
		<view>
			
			<uni-collapse accordion>
				<view class="titleText">分组名称</view>
				<uni-collapse-item  thumb="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png" :title="item.teamName" v-for="(item,index) in list">
					<block slot="title">
						<view class="contentList" @click="onShowData(item)">
							<view>
								<view>{{item.name}}( {{item.num != null ? item.num : '0'}} 只球队)</view>
							</view>
						</view>
					</block>
					<view class="contentBtn">
						<button @click="del(item)">移除分组</button>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import {
		getTeamGroupingList,
		putbasketballTeam,
		uploadAvatar,
		delteamGrouping
	} from '@/api/basketballTeam/index.js'
	import {imageUrl} from '@/config.js'
	export default {
		data() {
			return {
				list: [],
				pageData: {
					pageSize: 10,
					pageNum: 1
				},
				total: 0,
				loadingType: 'more',
			}
		},
		methods: {
			clickLeft() {
				uni.navigateBack()
			},
			del(item) {
				uni.showModal({
					content: '确定移除吗？',
					success: (res) => {
						if (res.confirm) {
							delteamGrouping(item.id).then(res => {
								this.list = []
								this.pageData = {
									pageSize: 10,
									pageNum: 1
								}
								this.getList();
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			onCreated() {
				uni.navigateTo({
					url: '/pages/createGroup/create'
				})
			},
			onShowData(item) {
				uni.navigateTo({
					url: '/pages/createGroup/group?id=' + item.id + '&name=' + item.name
				})
			},
			getList() {
				getTeamGroupingList().then(res => {
					console.log(res,"res---------")
					this.total = res.total
					this.list.push(...res.rows)
					if (this.list.length == this.total) {
						this.loadingType = 'no-more'
						return;
					}
				})
			}
		},
		async onReachBottom() {
			if (this.list.length == this.total) {
				this.loadingType = 'no-more'
				return;
			}
			this.loadingType = 'loading'
			this.pageData.pageNum += 1
			this.getList()
		},
		onShow() {
			this.pageData = {
				pageNum: 1,
				pageSize: 10
			}
			this.list = []
			this.getList();
		}
	}
</script>

<style scoped lang="scss">
.titleText{
	background: #f9fafc;
	padding: 20rpx 30rpx;
}
.contentList {
	display: flex;
	padding: 30rpx;
	align-items: center;
	font-weight: 600;
}
</style>